<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">
var index=0;
var pageId="";
function save(){
	    var v="";
	  var tb=document.getElementById("table");
	  var len=tb.rows.length;
	  if(len<=1){
		  alert("参数列表不可为空");
		  return;
	  }
		var arr=document.getElementsByName("check");
		for(i=0;i<arr.length;i++){
			//  if(arr[i].checked){
				 var a=arr[i].value;
				 var sz=a.split(","); 
				 v=v+sz[0]+','+
					sz[1]+','+	
					sz[2];
		    // }
			v=v+';';
		 }
			 
    	   $.ajax({
  			type:'post',
  			url:'${pageContext.request.contextPath }/plupmodule/updateModulePage?v='+v,
  		    dataType: "json",
  		    data:$("#form").serialize(),
  		    async: false,
  			success:function(data){//返回json结果
      			var addstate=data.model.flag;
      			if(addstate==0){
      				alert("修改失败");
      			}else{
      				alert("修改成功");
      				//window.location.href="${pageContext.request.contextPath }/plupmodule/modulelist";
          			}
  			}
  			
  		});
  	 
         }

function rowClickAfter(rowIndex,curModuleId, curAppName) {
	pageId=curModuleId;
	var  arrId = document.getElementsByName("check");
	arrId[rowIndex -1 ].checked=true;
}
function addrow()
{
        var html=window.showModalDialog("${pageContext.request.contextPath }/plupmodule/modulepagelist?module_id=${module_id}",window,"dialogwidth:1200px;   dialogheight:650px;   center:yes;   Help:No;   Resizable:No;   Status:Yes;   Scroll:Yes;   Status:no;   resizable:no ");
        $("table").append(html); 
	  
}
function deleteModule(){
	if(index==0){
		alert("请选择一条");
	}else{
		document.getElementById("table").deleteRow(index);
		$.ajax({
  			type:'post',
  			url:'${pageContext.request.contextPath }/plupmodule/delPage',
  		    dataType: "json",
  		    data:{'moduleid':'${module_id }', 'pageid':pageId},
  		    async: false,
  			success:function(data){//返回json结果
  				var fl=data.flag;
     			if(fl==0){
     				alert("删除失败！");
     			}else{
     				alert("删除成功");
         		} 
  			}
  		});
	}
}
function setbgColor(index){
	var tr= document.getElementsByTagName("tr");
	for(var i=0; i<tr.length ; i++){
			if(i==index){
					tr[i].style.backgroundColor="#FFCCCC";
			}else{
					tr[i].style.backgroundColor="#ffffff ";
			}
	}
} 
function  selectModule(r,index1){
	var i=r.rowIndex;
	index=i;
}

function doPageEdit(){
	if (pageId == "") {
		alert("请选择要制作的页面！");
	} else {
		//window.location.href="${ctx}/pagemgr/edit?page_id="+pageId;
		document.getElementById("linkPage").href = "${ctx}/pagemgr/edit?page_id="+pageId;
		document.getElementById('linkPage').click();			
	}
}
 
</script>
 
</head>
<body >
<form class="form-horizontal" role="form" id="form" name="form"  method="post">
                       <c:if test="${viewState==0}">
                        <input type="button" onclick="addrow()" class="btn btn-default" value="添加"/>
                        <input type="button" onclick="deleteModule()" class="btn btn-default" value="移除"/>
                        <input type="button" onclick="Utils.forward('${ctx}/pagemgr/create?moduleid=${module_id }');" class="btn btn-default" value="创建页面"/>
                        <input type="button" onclick="doPageEdit()" class="btn btn-default" value="页面制作"/>
                        <a id="linkPage"  target="_blank"/></a>
                        </c:if>
                        <input type="hidden" id="strid" name="strid" class="form-control" value="${module_id}"/>
             <table  id="table"  class="table table-bordered"  style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center"  class="active">
						<th style="text-align: center">选择</th>
						<th style="text-align: center">页面标识</th>
						<th style="text-align: center">页面名称</th>
						<th style="text-align: center">页面制作方式</th>
						<th style="text-align: center">最近更新日期</th>			
					</tr>
					</thead>	
					<tbody>
				<c:forEach items="${smpList}" var="module" varStatus="s" >
					<tr onclick="selectModule(this,${s.index+1})"; align="center" class="row_module" id="${module.pageId}" >
						<td><input type="radio" name="check" id="check" value="${module.pageId},${module.pageName},${module.pageMakeMode}"></input></td>
					<td>${module.pageId}</td>
					<td>${module.pageName}</td>			
					<td><c:if test="${module.pageMakeMode==1}">模板配置生成</c:if>
					<c:if test="${module.pageMakeMode==2}">自定义页面</c:if>			</td>
					<td>${module.lastModifyDate}</td>
					</tr>
					</c:forEach>
				</tbody>
				</table>                     
                    <br></br>

					<div class="form-group">
						<div class="col-xs-5"></div>
						<div class="col-xs-5">
						 <c:if test="${viewState==0}">
							<button type="button" class="btn btn-default" onclick="save()">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>
							
							<button type="button" class="btn btn-default"  onclick="history.go(-1);">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>
						</c:if>
						</div>
					</div>
                    <br></br>
                </form>
<script language="javascript">
	    var preRow = null;
		$('tbody tr').bind('click', function() {
			var rowIndex = $(this).prevAll().length+1;
			if(rowIndex <1) return;
			
			if(preRow != null){
				preRow.removeClass("active");
			}
			$(this).addClass("active");
			preRow = $(this);
			
			// 行单击后事件(传入行号，应用ID,应用名称信息)
			rowClickAfter(rowIndex,
					$(this).find("td").eq(1).text(),$(this).find("td").eq(2).text());
		});
	</script>
</body>

</html>
